from confs.conf import get_production_conn
from datetime import datetime, timedelta
import requests



select = """
SELECT
	p.id as order_id,
  ( SELECT pp.meta_value FROM wp_postmeta pp WHERE pp.post_id = p.id AND pp.meta_key = '_shipping_email' ) AS 'email_address'
FROM
	wp_posts p
WHERE
	post_type = 'shop_order' 
	AND post_status = 'wc-completed' 
	AND post_modified_gmt >= '2024-11-18 00:00:00' 
	AND post_modified_gmt < '2024-11-19 00:00:00'
"""


def get_data():
    db_conn = get_production_conn()
    # 获取当前时间
    now = datetime.now()

    # 获取15天前的时间
    days_before = now - timedelta(days=15)

    print(days_before)
    # 获取15天前的零点时间
    midnight_before = datetime.combine(days_before.date(), datetime.min.time())
    print(midnight_before)

    sql = select

    r = db_conn.query_all(sql)

    print(r)

if __name__ == '__main__':
    get_data()